/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package argtrust.trustnet;

import argtrust.measure.Measure;
import java.util.List;
import java.util.ArrayList;

/**
 *
 * @author Yuqing Tang
 */
public class TrustNode {

    Agent mAgent;
    List<TrustLink> mTrustLinkList;
    /**
     * A list of inversed trust links.
     */
    List<TrustLink> mInvTrustLinkList;

    public TrustNode() {
        mTrustLinkList = new ArrayList<TrustLink>();
        mInvTrustLinkList = new ArrayList<TrustLink>();
    }

    public TrustNode(Agent agent) {
        this();
        mAgent = agent;
    }

    public void setAgent(Agent agent) {
        mAgent = agent;
    }

    public Agent getAgent() {
        return mAgent;
    }

    public void linkTrusteeNode(TrustNode other_node, Measure measure) {
        Trust trust = new Trust(mAgent, other_node.getAgent(), measure);

        TrustLink trust_link = new TrustLink(other_node, trust);
        mTrustLinkList.add(trust_link);

        TrustLink inv_trust_link = new TrustLink(this, trust);
        other_node.getInvTrustLinkList().add(inv_trust_link);
    }

    public List<TrustLink> getInvTrustLinkList() {
        return mInvTrustLinkList;
    }

    public List<TrustLink> getTrustLinkList() {
        return mTrustLinkList;
    }
    //---------------------------------------
    ///For dynamic programming usage.
    boolean isMark = false;

    public boolean isMark() {
        return isMark;
    }

    public void mark() {
        this.isMark = true;
    }

    public void unmark() {
        this.isMark = false;
    }

    public void unmarkHierarchy() {
        unmark();
        for (TrustLink trust_link : mTrustLinkList) {
            TrustNode next_node = trust_link.getTrusteeNode();
            if (next_node.isMark()) {
                next_node.unmarkHierarchy();
            }
        }

    }
    //---------------------------------------
}
